// 此文件用于产生项目中所展示的各种假数据

import React from "react";
import {string} from "prop-types";

interface DataType {
  key: React.Key;
  main: string;
  number: string;
  name: string;
  attribute: string;
  location: string;
  address: string;
  ownership: string;
  isImportant: boolean;
  note: string;
  editStatus?: boolean;
}

const generateWarehouseData = () => {
  interface SingleData {
    key: React.Key;
    data: DataType[];
  }

  interface Item {
    key: React.Key;
    data: SingleData[];
  }

  const address = ['杭州', '南昌', '广州', '深圳', '珠海', '南京', '义乌', '安徽', '上海', '北京', '其他'];
  const warehouseName = ['秦岭淮河仓库', '大兴安岭仓库', '昆仑山仓库', '天山仓库', '阴山仓库', '太行山仓库', '贺兰山仓库', '巴颜喀拉山仓库', '巫山仓库']

  // 格式化数字
  const formatNumber = (num: number): string => {
    return num.toString().padStart(3, "0");
  };

  const data: Item[] = new Array(60).fill(null).map((_, index) => ({
    key: index,
    data: [],
  }));

  // 遍历每个ItemData，并为其初始化SingleData及其内部的DataType数组
  for (let i = 0; i < data.length; i++) {
    const singleDataArray: SingleData[] = new Array(10).fill(null).map((_, innerIndex) => ({
      key: innerIndex,
      data: new Array(20).fill(null).map<DataType>((__, dataIndex) => ({
        key: `${i}-${innerIndex}-${dataIndex + 1}`,
        name: warehouseName[`${Math.floor(Math.random() * 9)}`],
        main: String(Math.floor(Math.random() * 3) + 1),
        number: `CK-${formatNumber(i + 1)}`,
        attribute: String(Math.floor(Math.random() * 3) + 1),
        location: String(Math.floor(Math.random() * 3) + 1),
        address: address[`${Math.floor(Math.random() * 10) + 1}`],
        ownership: String(Math.floor(Math.random() * 3) + 1),
        isImportant: false,
        note: "暂无备注",
        editStatus: false,
      })),
    }));

    data[i].data = singleDataArray;
  }

  return data;
};

const generateProjectData = () => {
  interface ProjectsDetail {
    key: string;
    // 在这里添加项目对象需要的5个属性
    name: string;
    age: string;
    task: string;
    address: string;
    description: ProjectsDetail[];
  }

  interface Item {
    key: string;
    serialNumber: number;
    projectNumber: string;
    name: string;
    creator: string;
    projectDetail: ProjectsDetail[]
  }

  const data: Item[] = [];

  // 公司名儿常量
  const nameConstant = ['吉峰三农科技服务股份有限公司', '天健会计事务所', '富士康科技有限公司',
    '阿里巴巴集团控股有限公司', '比亚迪集团', '小米集团', '天猫技术有限公司', '阿里云计算有限公司',
    '吉峰四农科技服务股份有限公司', '德勤会计事务所', '中国烟草总公司',
    '百度集团', '胜讯环球投资有限公司', '百度网盘', '华为技术有限公司', "华为技术有限公司浙江分公司",
    "北京抖音信息服务有限公司", "字节跳动人工智能实验室", '今日头条'
  ];
  // 执行与否常量
  const executeConstant = ['执行', '不执行'];
  // 地址常量
  const addressConstant = ['深圳子公司', '北京子公司', '浙江子公司', '珠海子公司', '上海子公司', '山东子公司', '南京子公司'];

  for (let i = 1; i <= 60; i++) {
    const project = {
      key: i.toString(),
      serialNumber: i,
      projectNumber: `HZ-${Date.now()}-${i}`,
      name: `这是我们的第 ${i} 个项目工程...`,
      creator: `Kafka_${Math.floor(Math.random() * 5) + 1}`,
      projectDetail: null,
    };

    // 以下给各个变量的task赋值，限定随机生成条件
    const mainRandomTask1 = Math.floor(Math.random() * 2);
    const mainRandomTask4 = Math.floor(Math.random() * 2);
    const mainRandomTask5 = Math.floor(Math.random() * 2);
    const subRandomTask1 = Math.floor(Math.random() * 2);
    const subRandomTask2 = Math.floor(Math.random() * 2);
    const subRandomTask3 = Math.floor(Math.random() * 2);
    const subRandomTask4 = Math.floor(Math.random() * 2);
    const subRandomTask5 = Math.floor(Math.random() * 2);
    const mainRandomTask2 = (subRandomTask1 === 1 && subRandomTask2 === 1) ? 1 : 0;
    const mainRandomTask3 = (subRandomTask3 === 1 && subRandomTask4 === 1 && subRandomTask5 === 1) ? 1 : 0;

    // 写入一级项目详情
    const detail: ProjectsDetail[] = [
      {
        key: `${i}-1`,
        name: nameConstant[`${Math.floor(Math.random() * 18) + 1}`],
        age: "",
        task: executeConstant[mainRandomTask1],
        address: mainRandomTask1 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-2`,
        name: nameConstant[`${Math.floor(Math.random() * 18) + 1}`],
        age: "",
        task: executeConstant[mainRandomTask2],
        address: mainRandomTask2 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 10`,
        description: []
      },
      {
        key: `${i}-3`,
        name: nameConstant[`${Math.floor(Math.random() * 18) + 1}`],
        age: "",
        task: executeConstant[mainRandomTask3],
        address: mainRandomTask3 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-4`,
        name: nameConstant[`${Math.floor(Math.random() * 18) + 1}`],
        age: "",
        task: executeConstant[mainRandomTask4],
        address: mainRandomTask4 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-5`,
        name: nameConstant[`${Math.floor(Math.random() * 18) + 1}`],
        age: "",
        task: executeConstant[mainRandomTask5],
        address: mainRandomTask5 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 11`,
        description: []
      },
    ];
    // 写入二级项目详情subDetail_2
    const subDetail_2: ProjectsDetail[] = [
      {
        key: `${i}-2-1`,
        name: addressConstant[`${Math.floor(Math.random() * 7)}`],
        age: "",
        task: executeConstant[subRandomTask1],
        address: subRandomTask1 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-2-2`,
        name: addressConstant[`${Math.floor(Math.random() * 7)}`],
        age: "",
        task: executeConstant[subRandomTask2],
        address: subRandomTask2 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
    ];
    // 写入二级项目详情subDetail_4
    const subDetail_3: ProjectsDetail[] = [
      {
        key: `${i}-3-1`,
        name: addressConstant[`${Math.floor(Math.random() * 7)}`],
        age: "",
        task: executeConstant[subRandomTask3],
        address: subRandomTask3 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-3-2`,
        name: addressConstant[`${Math.floor(Math.random() * 7)}`],
        age: "",
        task: executeConstant[subRandomTask4],
        address: subRandomTask4 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      },
      {
        key: `${i}-3-3`,
        name: addressConstant[`${Math.floor(Math.random() * 7)}`],
        age: "",
        task: executeConstant[subRandomTask5],
        address: subRandomTask5 === 1 ? "—" : `${Math.floor(Math.random() * 9) + 1} / 9`,
        description: []
      }
    ];
    detail[1].description = subDetail_2;
    detail[2].description = subDetail_3;
    const myPro = {...project, projectDetail: detail}
    data.push(myPro);
  }

  return data;
}

interface Project {
  companyJia: string,
  companyYi: string,
  contract: string,
  contractTime: [string, string],
  department: string,
  mangerName: string,
  projectName: string,
  projectType: string,
  isSupervise: string
}

const generateDefaultRecentProject = () => {

  const defaultRecentProject: Project[] = [];

  defaultRecentProject.push(
    {
      companyJia: '默认甲方公司',
      companyYi: '默认乙方公司',
      contract: '1234567890',
      contractTime: [Date.now().toString(), Date.now().toString()],
      department: '',
      mangerName: 'Kafka',
      projectName: '关于甲方公司的项目',
      projectType: '',
      isSupervise: 'yes'
    },
    {
      companyJia: '默认甲方公司',
      companyYi: '默认乙方公司',
      contract: '1234567890',
      contractTime: [Date.now().toString(), Date.now().toString()],
      department: '',
      mangerName: 'Kafka',
      projectName: '关于甲方公司的项目',
      projectType: '',
      isSupervise: 'yes'
    },
  )

  return defaultRecentProject;
}

export const DefaultRecentProject = generateDefaultRecentProject();

// 产生仓库数据
export const WarehouseData = generateWarehouseData();

// 产生项目数据
export const ProjectData = generateProjectData();

